package com.central.apps.controller;

import com.central.app.service.HandlerService;
import com.central.common.web.PageResult;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 采购台账付款申请单
 */
@RestController
@RequestMapping("/paymentapply")
public class PaymentapplyController {

    @Autowired
    private HandlerService handlerService;

    /**
     *
     * @return123456789
     */
    @GetMapping("/paymentapplyByPo")
    public PageResult<Map<String, Object>> paymentapplyByPo(@RequestParam Map<String,Object> params) throws Exception {
        Integer limit = MapUtils.getInteger(params, "limit");
        Integer page = MapUtils.getInteger(params, "page");
        String poid = MapUtils.getString(params, "poid");//采购订单id
        String sql = "SELECT DISTINCT a.docdate,a.payapplynum,a.id,a.paymenttype,a.paymentdate,a.paymentpercent,a.paymentexcamt,a.paymentamt FROM gq_paymentapply a LEFT JOIN gq_paypursumary b ON b.puid = a.id left JOIN gq_purchaseinvoice c on b.pinum = c.pinum LEFT JOIN gq_po d on c.ponum=d.ponum where a.`status`='已批准' and d.id= '" + poid + "'";
        PageResult<Map<String, Object>> mapPageResult = handlerService.pageList(page==null?1:page, limit==null?10:limit, sql);
        return mapPageResult;
    }
}
